package cn.com.xuhx.testMapper;


import cn.com.xuhx.mapper.UserMapper;
import cn.com.xuhx.pojo.User;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询测试
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class SelectTest {

    @Autowired
    private UserMapper userMapper;


    /**
     * 查询所有
     */
    @Test
    public void selectAll(){
        //SELECT id,name,age,address,tel,sfzh,bornday,delStatus FROM T_USERS WHERE delStatus=0
        List<User> users = userMapper.selectList(null);
        users.forEach((item) -> {
            System.out.println(item);
        });
    }

    /**
     * 根据ID查询
     */
    @Test
    public void selectByID(){
        //SELECT id,name,age,address,tel,sfzh,bornday FROM T_USERS WHERE id=?
        User user = userMapper.selectById(11L);
        System.out.println(user);
    }

    /**
     * 批量查询
     */
    @Test
    public void selectBatchIds(){
        //SELECT id,name,age,address,tel,sfzh,bornday FROM T_USERS WHERE id IN ( ? , ? , ? )
        List<User> users = userMapper.selectBatchIds(Arrays.asList(7L, 8L, 9L));
        System.out.println(users);
    }

    /**
     * 根据map条件查询
     */
    @Test
    public void selectByMap(){
        //SELECT id,name,age,address,tel,sfzh,bornday FROM T_USERS WHERE name = ? AND age = ?
        Map<String, Object> map = new HashMap<>();
        map.put("name","李四");
        map.put("age",24);
        List<User> users = userMapper.selectByMap(map);
        System.out.println(users);
    }


}
